﻿using System;
using System.Collections.Generic;
using System.Text;
using AspNetCs.IDAL;
using AspNetCs.Model;
using System.Data;
namespace AspNetCs.SQLServerDAL
{
    public class City_DAL : ICity
    {



        #region ICity 成员

        public City_Model GetModel(DataRow dr)
        {
            City_Model model = new City_Model();
            if (dr["id"] != null) model.Id = Convert.ToInt32(dr["id"]);
            if (dr["className"] != null) model.ClassName = dr["className"].ToString();
            if (dr["ProvinceID"] != null) model.ProvinceID = Convert.ToInt32(dr["ProvinceID"]);
            if (dr["ProvinceName"] != null) model.ProvinceName = dr["ProvinceName"].ToString();
            if (dr["Addtime"] != null) model.Addtime = Convert.ToDateTime(dr["Addtime"].ToString());
            return model;
        }

        public int Add(City_Model model)
        {
            int Result = -1;
            db ConnAdd = new db();
            try
            {
                ConnAdd.Execute_Noget("Insert into City(className,ProvinceID,ProvinceName) values('" + model.ClassName + "'," + model.ProvinceID + ",'" + model.ProvinceName + "')");
                Result = 0;
            }
            catch
            {
                Result = -1;
            }
            return Result;
        }

        public int update(City_Model model)
        {
            int Result = -1;
            db ConnAdd = new db();
            try
            {
                Result = ConnAdd.ExcSql("Update City Set className='" + model.ClassName + "' where id=" + model.Id + " ");
            }
            catch
            {
                Result = -1;
            }
            return Result;
        }

        public int delete(int id)
        {
            int Result = -1;
            db ConnAdd = new db();
            try
            {
                Result = ConnAdd.ExcSql("delete from  City  where id=" + id + " ");
            }
            catch
            {
                Result = -1;
            }
            return Result;
        }


        public DataTable CityList(int parentid)
        {
            DataTable dt = new DataTable();
            db Conndt = new db();
            dt = Conndt.GetSql_DataTable("Select * from City where ProvinceID=" + parentid+" order by addtime desc");
            return dt;
        }

 

        public void UpdateOrder(int id)
        {
            db Cn = new db();
            string Sql = "update City Set Addtime='" + DateTime.Now + "' where id=" + id + " ";
            Cn.Execute_Noget(Sql);
        }

        #endregion
    }
}
